package com.elitel.frame.web.cfgservergroup.controller;

import com.elitel.common.core.domain.JsonResult;
import com.elitel.frame.web.cfgservergroup.entity.CfgServerGroup;
import com.elitel.frame.web.cfgservergroup.service.CfgServerGroupService;
import com.elitel.frame.web.common.controller.ApiController;
import com.elitel.frame.web.common.domain.JsonTableResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 数据分组表(CfgServerGroup)表控制层
 *
 * @author makejava
 * @since 2025-05-20 09:31:30
 */
@RestController
@RequestMapping("cfgServerGroup")
public class CfgServerGroupController extends ApiController {
    /**
     * 服务对象
     */
    @Resource
    private CfgServerGroupService cfgServerGroupService;

    /**
     * 获取列表,不分页
     *
     * @param cfgServerGroup 筛选条件
     * @return 查询结果
     */
    @GetMapping("list")
    public JsonResult<List<CfgServerGroup>> list(CfgServerGroup cfgServerGroup) {
        return JsonResult.success(this.cfgServerGroupService.list(cfgServerGroup));
    }


    /**
     * 获取列表,分页
     *
     * @param cfgServerGroup 筛选条件
     * @return 查询结果
     */
    @GetMapping("listPage")
    public JsonTableResult<?> listPage(CfgServerGroup cfgServerGroup) {
        startPage();
        return getDataTable(this.cfgServerGroupService.list(cfgServerGroup));
    }

    @PostMapping("save")
    public JsonResult<CfgServerGroup> save(@RequestBody CfgServerGroup cfgServerGroup) {
        return JsonResult.success(this.cfgServerGroupService.save(cfgServerGroup));
    }


    @PostMapping("delete")
    public JsonResult delete(@RequestBody CfgServerGroup cfgServerGroup) {
        boolean b = this.cfgServerGroupService.deleteById(cfgServerGroup.getId());
        return b ? JsonResult.success() : JsonResult.error();
    }

}

